'''
Created on 2014-3-9

@author: xizhzhao
'''
class Record:
    def __init__(self):
        self.keyword = ''
        self.encode = 'UTF8'
        self.params = {}
        self.com_segs = {}
        self.job_info_segs = {}
        self.job_req_segs = {}
        self.time_segs = {}
        self.from_url = ''
        self.web_name = ''
    
    @staticmethod
    def compare_record(rcd1, rcd2):  # rcd1: db_record, record to insert
        compare_result = True
        if rcd1.encode == rcd2.encode and rcd1.from_url == rcd2.from_url and rcd1.web_name == rcd2.web_name:
            for key in rcd1.params.keys():
                if (rcd1.params[key] == None or ''.join(rcd1.params[key]) == '') and not rcd2.params.has_key(key):
                    compare_result = True
                elif not rcd2.params.has_key(key):
                    compare_result = False
                else:
                    compare_result = rcd1.params[key] == rcd2.params[key]
                if not compare_result:
                    return compare_result
            
            for key in rcd1.job_info_segs.keys():
                if (rcd1.job_info_segs[key] == None or ''.join(rcd1.job_info_segs[key]) == '') and not rcd2.job_info_segs.has_key(key):
                    compare_result = True
                elif not rcd2.job_info_segs.has_key(key):
                    compare_result = False
                else:
                    compare_result = rcd1.job_info_segs[key] == rcd2.job_info_segs[key]
                if not compare_result:
                    return compare_result
            
            for key in rcd1.job_req_segs.keys():
                if (rcd1.job_req_segs[key] == None or ''.join(rcd1.job_req_segs[key]) == '') and not rcd2.job_req_segs.has_key(key):
                    compare_result = True
                elif not rcd2.job_req_segs.has_key(key):
                    compare_result = False                
                else:
                    compare_result = rcd1.job_req_segs[key] == rcd2.job_req_segs[key]
                if not compare_result:
                    return compare_result
        else:
            compare_result = False
        return compare_result

    @staticmethod
    def is_dirct_info(attr_name):
        return attr_name in ['com_name', 'com_idsty', 'com_type', 'com_size',
                            'com_loc', 'com_cntct_tel', 'com_cntct_fax', 'com_cntct_web',
                            'com_cntct_qq', 'com_cntct_pst', 'com_cntct_brf', 'com_intro_p',
                            'job_info_name', 'job_info_hirenum', 'job_info_base', 'job_info_salary',
                            'job_rqrmt_edu', 'job_rqrmt_mjr', 'job_rqrmt_expr', 'job_desc_p',
                            'time_lupd', 'time_pstd', 'time_ed', 'time_effd']
    
    def is_expire_record(self):
        is_empty = True
        for key in self.params.keys():
            if key.startswith('job'):
                is_empty = self.params[key] == ''
                if not is_empty:
                    break
        return is_empty
